package com.nebula.item.service.service.serviceimpl;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.nebula.item.pojo.utils.CommonConstant;
import com.nebula.item.pojo.utils.pojo.CourseOralHealth;
import com.nebula.item.service.mapper.Selectmapper;
import com.nebula.item.service.service.Selectservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Author: llq
 * @Date: 2019/9/3
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SelectserviceImpl extends ServiceImpl<Selectmapper, CourseOralHealth> implements Selectservice {

    @Autowired
    Selectmapper selectmapper;

    @Override
    public Page<Map<String, Object>> selectPageService(Map<String, Object> map) {
        Integer current = MapUtil.getInt(map, "current");
        current = ObjectUtil.isNotNull(current)? current : CommonConstant.CURRENT_PAGE;
        Integer size = MapUtil.getInt(map, "size");
        size =  ObjectUtil.isNotNull(size)? size : CommonConstant.PAGE_SIZE;
        Page<Map<String, Object>> page = new Page<>(current, size);
        Integer delFlag = MapUtil.getInt(map, "delFlag");
        if(ObjectUtil.isNull(delFlag)){
            map.put("delFlag","0");
        }
        List<Map<String, Object>> maps = selectmapper.pageList(page, map);
        return page.setRecords(maps);
    }
}
